package com.qs.controller;

import com.qs.model.dto.OrderDto;
import com.qs.model.vo.OrderInfoVo;
import com.qs.response.Response;
import com.qs.service.ICartService;
import com.qs.service.IPayInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ClassName: OrderController
 * Package: com.qs.controller
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/3/30 - 14:32
 * @Version: v1.0
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

    private final ICartService cartService;
    private final IPayInfoService payInfoService;

    /**
     * 跳往支付订单页，查询订单详细数据（包含支付逻辑）
     * @param orderDto
     * @return
     */
    @PostMapping("/query")
    public Response queryOrderDetail(@RequestBody OrderDto orderDto){
        log.info("id为{}的用户正在进行订单详情查询请求...",orderDto.getUserId());
        OrderInfoVo orderInfo = cartService.queryOrderDetail(orderDto);
        log.info("id为{}的用户订单详情查询成功",orderDto.getUserId());
        return Response.success(orderInfo);
    }

    /**
     * 查询当前用户的待付款订单
     * @param userId
     * @return
     */
    @GetMapping("/query/wait/{userId}")
    public Response queryWaitPayOrder(@PathVariable("userId") Integer userId) {
        log.info("id为{}的用户正在进行待付款订单数据查询请求...",userId);
        List<OrderInfoVo> list = payInfoService.queryWaitPayOrder(userId);
        log.info("id为{}的用户正在进行待付款订单数据查询成功",userId);
        return Response.success(list);
    }

    /**
     * 查询当前用户的待付款订单数量
     * @param userId
     * @return
     */
    @GetMapping("/query/wait/count/{userId}")
    public Response queryWaitPayOrderCount(@PathVariable("userId") Integer userId) {
        log.info("id为{}的用户正在进行待付款订单数量查询请求...",userId);
        int count = payInfoService.queryWaitPayOrderCount(userId);
        log.info("id为{}的用户正在进行待付款订单数量查询成功",userId);
        return Response.success(count);
    }

    /**
     * 查询当前用户的历史订单数据
     * @param userId
     * @return
     */
    @GetMapping("/query/history/{userId}")
    public Response queryHistoryOrder(@PathVariable("userId") Integer userId) {
        log.info("id为{}的用户正在进行历史订单数据查询请求...",userId);
        List<OrderInfoVo> list = payInfoService.queryHistoryOrder(userId);
        log.info("id为{}的用户正在进行历史订单数据查询成功",userId);
        return Response.success(list);
    }
}
